﻿using System;
using System.ServiceProcess;
using System.Threading;
using Biz.Process;
using Biz.Properties;
using log4net;

namespace Biz
{
    public partial class BizProcessor : ServiceBase
    {
        private readonly ILog _log = LogManager.GetLogger(typeof(BizProcessor));
        int halfMinute = 1000 * 60 * 30;
        public BizProcessor()
        {
            InitializeComponent();
        }
        //test
        //public void Main()
        //{
        //    OnStart(null);
        //}
        /// <summary>
        /// 各路线程
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            //启动各路线程
            new Thread(Process).Start();

            _log.Info("各路线程启动完成...");
        }
        protected override void OnStop()
        {
            _log.Info("The processor Stoped!");
        }
        private void Process(object state)
        {
            while (true)
            {
                try
                {
                    BizFacade.SynFromHacToTinz();
                }
                catch (Exception ex)
                {
                    _log.Error(ex);
                }
                finally
                {
                    _log.Info("Next time seconds:" + halfMinute / 1000);
                    Util.ThreadSleep(halfMinute);

                }
            }
            // ReSharper disable once FunctionNeverReturns
        }


    }
}
